package com.zonta.finance.admin.controller;


import com.zonta.finance.common.dto.ApiResponse;
import com.zonta.finance.domain.form.CreateMenuForm;
import com.zonta.finance.domain.form.DelMenuForm;
import com.zonta.finance.domain.form.UpdateMenuForm;
import com.zonta.finance.domain.po.SysMenu;
import com.zonta.finance.domain.vo.GetMenuByIdVo;
import com.zonta.finance.domain.vo.ListTreeMenuVo;
import com.zonta.finance.domain.vo.ListTreeSelectMenuVo;
import com.zonta.finance.serivce.ISysMenuService;
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统菜单 前端控制器
 * </p>
 *
 * @author zonta
 * @since 2024-07-24
 */
@Api(tags = "系统菜单管理")
@RestController
@RequestMapping("/sysMenu")
@RequiredArgsConstructor
@Slf4j
public class SysMenuController {
    private final ISysMenuService sysMenuService;

    @ApiOperation(value = "树形菜单列表")
    @GetMapping(value = "/listTreeMenu")
    public ApiResponse<List<ListTreeMenuVo>> listTreeMenu(@RequestParam(required = false) String title) {
        return ApiResponse.success(sysMenuService.listTreeMenu(title));
    }

    @ApiOperation(value = "树形选择菜单列表")
    @GetMapping(value = "/listTreeSelectMenu")
    public ApiResponse<List<ListTreeSelectMenuVo>> listTreeSelectMenu() {
        return ApiResponse.success(sysMenuService.listTreeSelectMenu());
    }

    @ApiOperation(value = "获取菜单明细")
    @GetMapping(value = "/getMenuById")
    public ApiResponse<GetMenuByIdVo> getMenuById(@Validated @RequestParam @NotNull Integer id) {
        return ApiResponse.success(sysMenuService.getMenuById(id));
    }

    @ApiOperation(value = "创建菜单")
    @PostMapping(value = "/create")
    public ApiResponse<Boolean> create(@Validated @RequestBody CreateMenuForm form) {
        return ApiResponse.success(sysMenuService.create(form));
    }

    @ApiOperation(value = "修改菜单")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateMenuForm form) {
        return ApiResponse.success(sysMenuService.updateByForm(form));
    }

    @ApiOperation(value = "删除菜单")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Validated @RequestBody DelMenuForm form) {
        return ApiResponse.success(sysMenuService.del(form));
    }



}
